﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;

namespace IrishSettings.IntegrationTests
{
    public class TestPrincipal:IPrincipal
    {
        private readonly IIdentity userIdentity;

        public TestPrincipal(IIdentity identity)
        {
            userIdentity = identity;
        }

        public bool IsInRole(string role)
        {
            //Not very strict, eh.
            return true;
        }

        public IIdentity Identity
        {
            get { return userIdentity; }
        }
    }

    public class TestIdentity:IIdentity
    {
        private readonly string userName;
        private readonly bool userIsAuthenticated;

        public TestIdentity(string name, bool isAuthenticated)
        {
            userName = name;
            userIsAuthenticated = isAuthenticated;
        }

        public string Name
        {
            get { return userName; }
        }

        public string AuthenticationType
        {
            get { return "Test"; }
        }

        public bool IsAuthenticated
        {
            get { return userIsAuthenticated; }
        }
    }

    public class AuthUtils
    {

        public static void AuthByName(string name)
        {
            TestIdentity id = new TestIdentity(name,true);
            //If this was asp.net we'd also set Context.User
            Thread.CurrentPrincipal = new TestPrincipal(id);
        }
    }
}
